import Entity from './entity'
import { genIdSelector } from './genIdInSelector'

export default class Element extends Entity {
    constructor(db) {
        super(db, 'screenshots')
    }

    async getByPlanStepId({ planId, stepId, screenshotId }) {
        const entry = await this.find(Object.assign({ planId, stepId }, genIdSelector(screenshotId)))
        return entry
    }

    async addScreenshot(planId, suiteId, stepId, screenshot) {
        const newEntry = await this.insert({ planId, suiteId, stepId, screenshot, __skipClone__: 1 })
        return newEntry.insertedId.toString()
    }
}